package filters;
import java.io.*;
 
import javax.servlet.*;
import javax.servlet.http.*;
 

public class LoginFilter implements Filter {
   
  public void doFilter(ServletRequest req,
                       ServletResponse res,
                       FilterChain chain)
                       throws IOException,
                              ServletException {
	  HttpServletRequest request = (HttpServletRequest)req; 
	  HttpServletResponse response = (HttpServletResponse)res; 
	    
	   
	  if(request.getSession().getAttribute("userid")==null  &&  !request.getServletPath().equals(request.getContextPath()+"/index.jsp")) {
		  response.sendRedirect(request.getContextPath()+"/index.jsp");
		  return;
	  }
	  chain.doFilter(req, res);
  }
  public void init(FilterConfig filterConfig) {
	  
     
	   
  }
  
  public void destroy() {
	     
  }
}